<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="layout">

<div layout:fragment="body">
    <div id="toptoolbar"></div>
    <div id="searchformDiv">
        <form id='searchform' class="l-search-form">
            <div class="layui-inline">
                <input type="text" th:placeholder="#{channel.type}" liger="{type:'comboBox', valueFieldID:'search_EQ_type',configCode:'CHANNEL_TYPE_ENUM'}"/>
                <input id="search_EQ_type" name="search_EQ_type" style="display: none;">
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_code" th:placeholder="#{channel.code}"/>
            </div>
            <div class="layui-inline">
                <input type="text" class="l-text" name="search_LIKE_name" th:placeholder="#{channel.name}"/>
            </div>
            <div class="layui-inline">
                <input type="reset" class="l-reset" th:value="#{reset}" />
                <input type="button" class="l-search" th:value="#{search}" onclick="f_search();" />
            </div>
        </form>
    </div>
    <div id="maingrid"></div>
</div>

<!-- page specific plugin scripts -->
<script type="text/javascript" layout:fragment="script">/*<![CDATA[*/
var maingrid;
$(function() {
    maingrid = newGrid("maingrid", {
        columns : [
            {
                display : '[[#{channel.code}]]',
                name : 'code',
                align : 'left',
                width : 120
            },{
                display : '[[#{channel.name}]]',
                name : 'name',
                align : 'left',
                width : 120
            },{
                display : '[[#{channel.type}]]',
                name : 'config_type',
                align : 'center',
                width : 80
            },{
                display : '[[#{channel.pid}]]',
                name : 'pid_name',
                align : 'left',
                width : 120
            },{
                display : '[[#{channel.mobile}]]',
                name : 'mobile',
                align : 'center',
                width : 100
            },{
                   display : '[[#{createdAt}]]',
                name : 'createdAt',
                type : 'datetime',
                width : 120
            },{
                   display : '[[#{updatedAt}]]',
                name : 'updatedAt',
                type : 'datetime',
                width : 120
            }],
        url : '/channel/list'
    });

    $("#toptoolbar").ligerToolBar({
        items : [ {
            text : '增加',
            click : addClick,
            icon : 'add'
        }, {
            text : '修改',
            click : modifyClick,
            icon : 'modify'
        }, {
            text : '删除',
            click : deleteClick,
            icon : 'delete'
        }, {
            text : '查看',
            click : viewClick,
            icon : 'view'
        }, {
            line : true
        }, {
            text : '小程序二维码',
            click : qrCodeClick,
            icon : 'down'
        } , {
            text : 'H5二维码',
            click : qrCodeClick,
            icon : 'down'
        }]
    });

    maingrid.setHeight(document.documentElement.clientHeight - $("#toptoolbar").height() -  $("#searchform").height() - 18);
});

function addClick(item) {
    openForm({
        url: '/channel/form',
        title: '新增'
    });
}

function modifyClick(item) {
    isSingleSelected(maingrid, function(row) {
        openForm({
            url : '/channel/form?id=' + row['id'],
            title : '编辑'
        });
    });
}

function deleteClick(item) {
    isSingleSelected(maingrid, function(row) {
        showConfirm('确定要删除', function(yes) {
            if (yes) {
                ajaxDo('/channel/delete?id=' + row['id']);
            }
        });
    });
}

function viewClick(item) {
    isSingleSelected(maingrid, function(row) {
        openDialog({
            title: '查看',
            url : '/channel/view?id=' + row['id']});
    });
}

function qrCodeClick(item) {
    var type = item.text.indexOf("H5") != -1 ? "H5" : null;
    isSingleSelected(maingrid, function(row) {
        window.open('/channel/qrCode?id=' + row['id'] + "&type=" + type);
    });
}

function f_search() {
    loadGridData(maingrid, "searchform");
}

function f_reload() {
    maingrid.loadData(true);
}
/*]]>*/</script>
</html>
